package com.wufun.overseas.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;

import com.wufun.baselibrary.net.HttpUtils;
import com.wufun.overseas.rpc.RpcConstant;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * Created by Alan on 2017/12/19.
 */

public class PostNetDotUtil {

    //google 打点
    public static void PostNetDot(Context mContext, String Package_name, String Pid) {
        try {
            Map<String, String> map = new HashMap<String, String>();
            PackageManager pm = mContext.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), 0);
            map.put("client", pi.packageName + pi.versionCode);
            map.put("device", Build.DEVICE);
            map.put("os", AppDevicesUtil.getOS());
            String ipadd = AppDevicesUtil.getIPAddress(mContext);
            map.put("link", Pid);
            map.put("ip", ipadd);
            map.put("package_name", Package_name);
            HttpUtils.doPost(RpcConstant.forumRootUrl + "/Google_middleware/main", map, new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {
                    e.printStackTrace();
                    Log.e("PostNetDot", "失败:" + e.getMessage());
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    Log.e("PostNetDot", "成功！");
                }
            });
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

    }

    //标题 打点
    public static void PostTitleNetDot(Context mContext, String Package_name, String Pid) {
        try {
            Map<String, String> map = new HashMap<String, String>();
            PackageManager pm = mContext.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), 0);
            map.put("client", pi.packageName + pi.versionCode);
            map.put("device", Build.DEVICE);
            map.put("os", AppDevicesUtil.getOS());
            String ipadd = AppDevicesUtil.getIPAddress(mContext);
            map.put("link", Pid);
            map.put("ip", ipadd);
            map.put("package_name", Package_name);
            HttpUtils.doPost(RpcConstant.forumRootUrl + "/forum/switch_application/main", map, new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {
                    e.printStackTrace();
                    Log.e("PostTitleNetDot", "失败:" + e.getMessage());
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    Log.e("PostTitleNetDot", "成功！");
                }
            });
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

    }
}
